package com.atguigu.flink0624.chapter11;

import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.table.api.bridge.java.StreamTableEnvironment;
import org.apache.flink.table.catalog.hive.HiveCatalog;

/**
 * @Author lizhenchao@atguigu.cn
 * @Date 2021/11/19 10:26
 */
public class Flink14_hive {
    public static void main(String[] args) throws Exception {
        System.setProperty("HADOOP_USER_NAME", "atguigu");
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(1);
        
        StreamTableEnvironment tenv = StreamTableEnvironment.create(env);
        
        // 1. 创建hive catalog
        HiveCatalog hiveCatalog = new HiveCatalog("hive", "gmall", "input/");
        // 2. 注册 hive catalog
        tenv.registerCatalog("hive", hiveCatalog);
        tenv.useCatalog("hive");
        tenv.useDatabase("gmall");
        // 3. 使用hive catalog读取hive中的数据
        tenv
            .sqlQuery("select" +
                          " * " +
                          "from person")
            .execute()
            .print();
        
    }
}
